<?php

use think\facade\Route;
use think\facade\Config;
use think\Response;
use app\admin\middleware\LoginMiddleware;
use app\admin\middleware\AuthMiddleware;
use app\admin\middleware\OperationLog;

/**
 * 无需校验的接口
 */
Route::group(function () {
    //账号登录
    Route::post('login', 'login.Login/login');
    //基础配置
    Route::get('getConfig', 'login.Config/getConfig');
    //创建验证码
    Route::get('captcha/create', 'login.Captcha/create');
    //创建验证码图片
    Route::get('captcha/codeCreate', 'login.Captcha/codeCreate');
    //一次校验验证码
    Route::post('captcha/check', 'login.Captcha/check');
});

Route::post('logout', 'login.Login/logout')->middleware([
    LoginMiddleware::class,
    AuthMiddleware::class,
    OperationLog::class
]);

/**
 * miss 路由
 */
Route::miss(function () {
    if (app()->request->isOptions()) {
        $header = Config::get('cookie.header');
        $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
        return Response::create('ok')->code(200)->header($header);
    } else
        return Response::create()->code(404);
});